import JiraService from '../Services/JiraService';
import CONSTANTDATA from '../Tools/ResConstant';
var { request, summary, body, description, tags } = require('koa-swagger-decorator');



class JiraControllers {

@tags(['Jira'])
@request('get', '/jira/bug/pandect')
@summary('总览数据')
//@body(userSchema)
@description('返回jira总览数据')
  async bugPandect(ctx) {
    const ret = await JiraService.pandect();

    if (!ret) {

      /*       module.exports = {
              CODE_SUCCESS: {
                code: 0,
                message: '请求成功'
              },
              CODE_ERROR: {
                code: -1,
                message: '请求失败'
              },
            }; */
      ctx.body = ctx.constantResData(CONSTANTDATA.CODE_ERROR);
      return;
    };

    ctx.body = ctx.constantResData(CONSTANTDATA.CODE_SUCCESS, ret);
  };



  async singleProjectData(ctx) {
   
    let projectid = ctx.params.projectid
    const ret = await JiraService.SinglePandect(projectid)
    if (!ret) {
      ctx.body = ctx.constantResData(CONSTANTDATA.CODE_ERROR);
      return;
    };

    ctx.body = ctx.constantResData(CONSTANTDATA.CODE_SUCCESS, ret);
  };



  async QualityFactorArry(ctx){

    const ret  = await JiraService.QualityFactor()
    if (!ret){
      ctx.body =ctx.constantResData(CONSTANTDATA.CODE_ERROR)
      return;
    }
    ctx.body = ctx.constantResData(CONSTANTDATA.CODE_SUCCESS, ret);

  };

  
  async eachProjectJiraDb(ctx){

   let year= ctx.params.year
   let projectid= ctx.params.projectid
    const ret =await JiraService.JiraDbModelEachM(year,projectid)
    if(!ret){
      ctx.body =ctx.constantResData(CONSTANTDATA.CODE_ERROR)
      return;
    }
    ctx.body = ctx.constantResData(CONSTANTDATA.CODE_SUCCESS, ret);
    
  };


  async allProjectJiraDb(ctx){

    let year= ctx.params.year
    const ret =await JiraService.jiraDbModelAllM(year)
    if(!ret){
      ctx.body =ctx.constantResData(CONSTANTDATA.CODE_ERROR)
      return;
    }
    ctx.body = ctx.constantResData(CONSTANTDATA.CODE_SUCCESS, ret);

  }
  
};


module.exports = new JiraControllers();